package com.zhuiyun.project.api.friend.controller;


import com.zhuiyun.project.api.friend.entity.Friend;
import com.zhuiyun.project.api.friend.model.FriendModel;
import com.zhuiyun.project.api.friend.service.FriendService;
import com.zhuiyun.project.common.response.CommonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName FriendController
 * @Description TODO 好友 controller
 * @Author kdj
 * @Date 2023/6/20 14:21
 **/
@RestController
@CrossOrigin
@RequestMapping("/friend")
public class FriendController {

    @Autowired
    private FriendService friendService;

    /**
     * @param name
     * @param userId
     * @Author kdj
     * @Description 根据name模糊查好友
     * @Date 2023/6/21 10:02
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/getFriendByNameLike")
    @ApiOperation(value = " 根据name模糊查好友")
    public CommonResult getFriendByNameLike(String name, int userId) {
        return friendService.getFriendByNameLike(name, userId);
    }

    /**
     * @param userId
     * @Author kdj
     * @Description 根据好友id获取好友信息
     * @Date 2023/6/21 11:26
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/getFriendByFriendUserId")
    @ApiOperation(value = " 根据好友id获取好友信息")
    public CommonResult getFriendByFriendUserId(int userId,int friendId) {
        return friendService.getFriendByFriendUserId(userId,friendId);
    }


    /**
     * @param userId
     * @param friendId
     * @Author kdj
     * @Description 判断是否为朋友关系
     * @Date 2023/7/20 21:16
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/isFriend")
    @ApiOperation(value = " 判断是否为朋友关系")
    public CommonResult isFriend(int userId, int friendId) {
        return friendService.isFriend(userId, friendId);
    }


   /**
    * 聊天免打扰功能
    * @author 温
    * @date 2023/7/23 19:40
    * @parameter [friend]
    * @return com.zhuiyun.project.common.response.CommonResult
    */
    @PostMapping("updateMeted")
    public CommonResult updateMeted(@RequestBody Friend friend){
        int i = friendService.updateMeted(friend);
        return CommonResult.ok(i);
    }



    /**
     * 修改好友备注
     * @author 温
     * @date 2023/7/24 10:48
     * @parameter [friend]
     * @return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/friendUpdate")
    public CommonResult friendUpdate( @RequestBody Friend friend ){
        int i = friendService.friendUpdate(friend);
        return CommonResult.ok(i);
    }



    /**
     * 获取好友列表
     * @author 温
     * @date 2023/7/27 20:57
     * @parameter [userId]
     * @return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/selectFriend")
    public CommonResult selectFriend(Friend friend){
        List<FriendModel> friendModels = friendService.selectFriend(friend);
        return CommonResult.ok(friendModels);
    }



    /**
     * 获取群聊列表信息
     * @author 温
     * @date 2023/8/1 18:32
     * @parameter [userId, groupName]
     * @return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/quancha")
    public CommonResult quancha(Integer userId,String groupName,Integer groupId){
        List<FriendModel> quancha = friendService.quancha(userId, groupName,groupId);
        return CommonResult.ok(quancha);
    }

}